<template>
    <!-- <div class="mui-numbox" data-numbox-min='1' data-numbox-max='9'> -->
    <div class="mui-numbox" data-numbox-min="1">
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input class="mui-input-numbox" type="number" :value="initCount" @change="countChange" ref="numbox"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
import mui from '../../lib/mui/js/mui.min.js';

export default {
    mounted() {
        // 初始化
        mui('.mui-numbox').numbox()
    },
    methods: {
        // 监听文本框变化，数据被修改的传参
        countChange(){
            // 传递参数给父组件
            this.$emit('getValue',parseInt(this.$refs.numbox.value));
            // 传递参数给store
            this.$store.commit('upDateCar',{
                id: this.goodsId,
                count: this.$refs.numbox.value
            })
        }
    }, 
    watch: {
        // 属性监听，动态设置最大值
        maxValue: function(newVal, oldVal) {
            mui(".mui-numbox").numbox().setOption("max", newVal);
        }
    },
    props: ['maxValue','initCount','goodsId']
}
</script>

<style lang="less" scoped>
    
</style>